$(function() {
    var form = layui.form
    form.verify({
        len: [/^\w{6,12}$/, '密码长度必须6-12位，且不能有空格'],
        diff: function(val) {
            var oldPwd = $('input[name="oldPwd"]').val()
            if (val === oldPwd) {
                return '原密码与新密码相同，请重新输入'
            }
        },
        same: function(value) {
            var newPwd = $('input[name="newPwd"]').val()
            if (newPwd !== value) {
                return '两次密码不一致'
            }
        }
    })
    $('form').on('submit', function(e) {
        e.preventDefault()
        $.ajax({
            type: 'POST',
            url: '/my/updatepwd',
            data: $(this).serialize(),
            success: function(res) {
                layer.msg(res.message)
                if (res.status === 0) {
                    // $('form').val('')
                    $('form')[0].reset()
                }
            }
        })

    })

})